/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.fastaconverter;

import com.compomics.fastaconverter.triplet.TripletFactory;
import com.compomics.fastaconverter.triplet.TripletConverter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Kenneth
 */
public class DNAtoAAConverter {

    private static String startAA = "M";
    private static boolean includeUnlikely = false;
    private static int unlikelyTreshold = 15;

    public static void main(String[] args) {
        TripletFactory.initialize();
        //new LogoPrinter().printLogo();
        File input = null;
        File output = null;

        try {
            int i = 0;
            List<String> commandList = new ArrayList<String>();
            for (String aCmd : args) {
                commandList.add(aCmd);
            }
            for (String aCmd : commandList) {
                if (aCmd.toLowerCase().equals("-output") && commandList.size() != commandList.indexOf(aCmd)) {
                    String outputName = commandList.get(commandList.indexOf(aCmd) + 1);
                    output = new File(outputName);
                }

                if (aCmd.toLowerCase().equals("-input") && commandList.size() != commandList.indexOf(aCmd)) {
                    String inputName = commandList.get(commandList.indexOf(aCmd) + 1);
                    input = new File(inputName);
                }

                if (aCmd.toLowerCase().equals("-start_triplet") && commandList.size() != commandList.indexOf(aCmd)) {
                    String triplet = commandList.get(commandList.indexOf(aCmd) + 1);
                    startAA = TripletFactory.getTripletSingleLetter(triplet);
                }

                if (aCmd.toLowerCase().equals("-start_single_letter") && commandList.size() != commandList.indexOf(aCmd)) {
                    startAA = commandList.get(commandList.indexOf(aCmd) + 1);
                }

                if (aCmd.toLowerCase().equals("-include_unlikely") && commandList.size() != commandList.indexOf(aCmd)) {
                    includeUnlikely = Boolean.parseBoolean(commandList.get(commandList.indexOf(aCmd) + 1).toLowerCase());
                }

                if (aCmd.toLowerCase().equals("-include_unlikely_treshold") && commandList.size() != commandList.indexOf(aCmd)) {
                    unlikelyTreshold = Integer.parseInt(commandList.get(commandList.indexOf(aCmd) + 1));
                }

            }
            if (input != null && output != null) {
                System.out.println("Converting fasta ! ");
                TripletConverter converter = new TripletConverter(input, output);
                converter.setStart(startAA);
                converter.setIncludeUnlikely(includeUnlikely);
                converter.setUnlikelyTreshold(unlikelyTreshold);
                try {
                    converter.convertFrame();
                    System.out.println("Conversion completed !");
                } catch (Exception ex) {
                    System.out.println("Conversion failed !");
                }
            }
        } catch (Exception e) {
            System.out.printf("%-15s %15s %n", "-output", "Specify the output file");
            System.out.printf("%-15s %15s %n", "-input", "Specify the input file");
            System.out.printf("%-15s %15s %n", "-start_triplet", "specify the start triplet (default = ATG", "WARNING do not use in combination with the single letter notation !");
            System.out.printf("%-15s %15s %n", "-start_single_letter", "specify the start letter (default = M)");
            System.out.printf("%-15s %15s %n", "-include_unlikely", "true or false - determines if shorter sequences are to be included (default = false)");
            System.out.printf("%-15s %15s %n", "-include_unlikely_treshold", "integer - determines the treshold for shorter sequences (default = 15)");
        }
    }
 }
